/**
 * Created by Administrator on 2017/3/21.
 */
import React, { Component,Fragment } from 'react';
import {Form, Input, DatePicker, Select, InputNumber, Button, Tooltip, Icon, Alert, Modal} from 'antd';
import { connect } from 'dva';
import moment from 'moment';
import request from '@/utils/request';
import find from 'lodash/find';

const FormItem = Form.Item;
const Option = Select.Option;
let uuid = 10;

class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      meterArr: [1, 2, 3, 4, 5, 6, 7, 8],
      meterActiveKey: ['1', '2', '3', '4', '5', '6', '7', '8'],
      meter1: [],
      meter2: [],
      meter3: [],
      meter4: [],
      meter5: [],
      meter6: [],
      meter7: [],
      meter8: [],
      all_concentrator_firmwares:[]
    };
  }


  componentDidMount() {
    const that = this;
    if(this.props.type==='update'){
      request(`/all_concentrator_firmwares`, {
        method: 'GET',
      }).then((response) => {
        if (response.status === 200) {
          that.setState({
            all_concentrator_firmwares:response.data.data
          })
        }

      });
    }

  }


  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
    };

    const { getFieldDecorator } = this.props.form;
    return (
      <div>
        {
          this.props.type === 'addImei' &&
          <Form>
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               平台
            </span>
              )}
            >
              {getFieldDecorator('platform', {
                initialValue: (this.props.editRecord && this.props.editRecord.config.platform) ? this.props.editRecord.config.platform : '',
                rules: [{required: true, message: '请输入平台'}],
              })(
                <Select >
                  <Option value={'生产管理-电信'}>生产管理-电信</Option>
                  <Option value={'生产管理-移动'}>生产管理-移动</Option>
                  <Option value={'天源水务-电信'}>天源水务-电信</Option>
                  <Option value={'天源水务-移动'}>天源水务-移动</Option>
                  <Option value={'山河水务-电信'}>山河水务-电信</Option>
                  <Option value={'山河水务-移动'}>山河水务-移动</Option>
                  <Option value={'风城水务-电信'}>风城水务-电信</Option>
                  <Option value={'风城水务-移动'}>风城水务-移动</Option>
                </Select>
              )}
            </FormItem>
            <FormItem
              {...formItemLayoutWithLabel}
              label={(
                <span>
               IMEI
            </span>
              )}
            >
              {getFieldDecorator('imei', {
                initialValue: this.props.editRecord ? this.props.editRecord.imei : '',
                rules: [{required: true, message: '请输入IMEI'}],
              })(
                <Input />
              )}
            </FormItem>
          </Form>
        }
        {
          this.props.type === 'update' &&
              <Form>
                <FormItem
                  {...formItemLayoutWithLabel}
                  label={(
                    <span>
               固件版本
            </span>
                  )}
                >
                  {getFieldDecorator('concentrator_firmware_id', {
                    initialValue: this.props.editRecord ? this.props.editRecord.version : '',
                    rules: [{required: true, message: '请选择固件版本'}],
                  })(
                    <Select >
                      {this.state.all_concentrator_firmwares.map((item,index)=>{
                      return  <Option key={index} value={item.id}>{item.version}</Option>
                    })}

                    </Select>
                  )}
                </FormItem>
              </Form>

        }


      </div>

    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


